/* @flow */

import React, { Component } from 'react';
import {
  View,
  Text,
  StyleSheet,
  FlatList,
  SectionList,
  ScrollView,
} from 'react-native';
import TextView from './TextView'

var keys = ["hospitalName","hospitalCode","orderFormNum", "orderFormDevNum", "oderFormSuccNum","oderFormFocusedNum","newAddUserNum", "portalPV", "wePV", "weUV","fetchFansNum", "PVUVDevide", "weUpRate",  "fetchFansRate", "pageOpenRate"]

// var keys = ["date","orderFormNum", "orderFormDevNum", "oderFormSuccNum","oderFormFocusedNum","newAddUserNum", "portalPV", "wePV", "weUV","fetchFansNum", "PVUVDevide", "weUpRate",  "fetchFansRate", "pageOpenRate"]

export default class ContentTableList extends Component {
  static propTypes = {

  }
  static defaultProps = {
    itemStyle:{},
    textStyle:{},
    keys:[],

  }
  constructor(props){
  	super(props);
  	this.state = {};
  }
  componentDidMount() {
    // console.log(this.props.data[0].wePV);
  }

  render() {
    return (
      <View style={[styles.container,this.props.style]}>
        <ScrollView ref='vertical' horizontal={true} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false}>
          {this._renderTable()}
        </ScrollView>
      </View>
    );
  }
  _renderTable = (data) => {
    var lists = []
    data = this.props.data;
    for (let i = 0; i < data.length; i++) {
      var item = data[i];
      // 创建视图
      lists.push(
        <View key={i}>
          {this._creatList(item)}
        </View>
      )

    }

    return lists;
  }
  _creatList = (data) => {
    var listItemViews = new Array()

    if (this.props.keys.length>1) {
      console.log('用属性');
      keys = this.props.keys;
    }else {
      console.log('用默认值');
    }

    for (var i = 0; i < keys.length; i++) {
      var key = keys[i]
      listItemViews.push(
        <TextView
          key={i}
          text={data[keys[i]]}
          textStyle={[{fontSize:12},this.props.textStyle]}
          style={[{backgroundColor:'rgb(255, 255, 255)',width:80,height:40,borderWidth:0.5,borderColor:'rgb(57, 60, 57)',justifyContent:'center',alignItems:'center'},{marginLeft:(i!=0?-1:-1),marginTop:i!=0?-1:0},this.props.itemStyle]}
        ></TextView>)
    }

    return listItemViews;

  }

}


const styles = StyleSheet.create({
  container: {

  },
  tableView:{
    flexDirection:'row',
  },
  tableItem:{
    flexDirection:'column'
  }
});
